using Microsoft.EntityFrameworkCore;
using PandaWebAPI.Models.ef;

namespace PandaWebAPI.Services
{
    public class ProductService : BaseService<Product>, IProductService
    {
        public ProductService(PandaSystemContext context) : base(context)
        {
        }

        public async Task<List<Product>> GetByCategoryAsync(Guid categoryId)
        {
            return await _dbSet
                .Where(p => p.CategoryId == categoryId)
                .ToListAsync();
        }

        public async Task<List<Product>> SearchAsync(string keyword)
        {
            if (string.IsNullOrEmpty(keyword))
                return await GetAllAsync();

            return await _dbSet
                .Where(p => (p.Name != null && p.Name.Contains(keyword)) || 
                           (p.Description != null && p.Description.Contains(keyword)))
                .ToListAsync();
        }
    }
} 